﻿using Mvc.XForms.Actions;

namespace Mvc.XForms.Controls.Settings {
	public class Select1Settings {
		public ISelect1 Select1 { get; set; }

		public Select1Settings(ISelect1 select1) {
			Select1 = select1;
		}

		public Select1Settings Label(string label) {
			Select1.Label = label;
			return this;
		}

		public Select1Settings Help(string help) {
			Select1.Help = help;
			return this;
		}

		public Select1Settings Hint(string hint) {
			Select1.Hint = hint;
			return this;
		}

		public Select1Settings Appearance(Appearance appearance) {
			Select1.Appearance = appearance;
			return this;
		}

		public Select1Settings ReadOnly() {
			return ReadOnly(true);
		}

		public Select1Settings ReadOnly(bool readOnly) {
			Select1.ReadOnly = readOnly;
			if (readOnly)
				Select1.CssClass.Add("readonly");
			return this;
		}

		public Select1Settings Required() {
			return Required(true);
		}

		public Select1Settings Required(bool required) {
			Select1.Required = required;
			if (required)
				Select1.CssClass.Add("required");
			return this;
		}

		public Select1Settings Relevant(bool relevant) {
			Select1.Relevant = relevant;
			return this;
		}

		public Select1Settings ID(string clientID) {
			Select1.ClientID = clientID;
			return this;
		}

		public Select1Settings CssClass(string cssClass) {
			Select1.CssClass.Add(cssClass);
			return this;
		}

		public Select1Settings Nullable() {
			return Nullable(string.Empty);
		}

		public Select1Settings Nullable(string nullText) {
			Select1.NullText = nullText;
			return this;
		}

		public Select1Settings SelectNullForEmptyRequest(bool selectNullForEmptyRequest) {
			Select1.SelectNullForEmptyRequest = selectNullForEmptyRequest;
			return this;
		}

		public Select1Settings Action(XFormEvent xformsEvent, string jsFunction) {
			var action = new ActionAction() {
				Event = xformsEvent,
				JSFunction = jsFunction
			};
			Select1.Actions.Add(action);
			return this;
		}

		public override string ToString() {
			return Select1.ValidateThenRender();
		}
	}
}
